package defpackage; import android.content.Context; import android.os.SystemClock; import cn.wps.moffice.crash.handler.CrashExtraInfo; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FilenameFilter; import java.io.PrintWriter; import java.io.StringWriter; import java.util.HashMap; /* renamed from: eic reason: default package */ public final class eic extends Thread { private static long eRM = 20971520; private static long eRN = 5242880; private boolean cfZ; private Throwable eRO; private String eRP; private String eRQ; private boolean eRR; private boolean eRS; private String eRT; public boolean eRU; public a eRV; private String eRs; private String eRu; private CrashExtraInfo eRv; private Context mContext; /* renamed from: eic$a */ public interface a { void onFinish(); } public eic(Context context) { this.cfZ = false; this.eRS = true; this.eRU = false; this.mContext = context; this.eRO = null; this.eRP = null; this.eRs = null; this.eRQ = null; this.eRR = false; } public eic(Context context, String str, String str2) { this(context, str, str2, (String) null, false, "none"); } public eic(Context context, String str, String str2, String str3, boolean z, String str4) { this.cfZ = false; this.eRS = true; this.eRU = false; this.mContext = context; this.eRO = null; this.eRP = str; this.eRs = str2; this.eRQ = str3; this.eRR = z; this.eRu = str4; } public eic(Context context, String str, String str2, String str3, boolean z, String str4, CrashExtraInfo crashExtraInfo) { this.cfZ = false; this.eRS = true; this.eRU = false; this.mContext = context; this.eRO = null; this.eRP = str; this.eRs = str2; this.eRQ = str3; this.eRR = z; this.eRu = str4; this.eRv = crashExtraInfo; } public eic(Context context, Throwable th, String str) { this(context, th, str, (String) null, false, "none"); } public eic(Context context, Throwable th, String str, String str2, boolean z, String str3) { this.cfZ = false; this.eRS = true; this.eRU = false; this.mContext = context; this.eRO = th; this.eRP = null; this.eRs = str; this.eRQ = str2; this.eRR = z; this.eRu = str3; } private void F(File file) { if (file.isFile()) { file.delete(); } else if (file.isDirectory()) { File[] listFiles = file.listFiles(); if (listFiles == null || listFiles.length == 0) { file.delete(); return; } for (File file2 : listFiles) { F(file2); } file.delete(); } } private static long G(File file) { if (!file.exists()) { return 0; } try { return (long) new FileInputStream(file).available(); } catch (Exception e) { e.printStackTrace(); return 0; } } private static void a(File file, File file2, boolean z) { if (file.exists() && file.isFile() && file.canRead()) { if (!file2.getParentFile().exists()) { file2.getParentFile().mkdirs(); } if (file2.exists()) { file2.delete(); } try { FileInputStream fileInputStream = new FileInputStream(file); FileOutputStream fileOutputStream = new FileOutputStream(file2); byte[] bArr = new byte[1024]; while (true) { int read = fileInputStream.read(bArr); if (read > 0) { fileOutputStream.write(bArr, 0, read); } else { fileInputStream.close(); fileOutputStream.close(); return; } } } catch (Exception e) { e.printStackTrace(); } } } private void aXx() { File parentFile; File[] listFiles; if (aXy() && (listFiles = (parentFile = new File(new File(oA("temp").toString()).getPath()).getParentFile()).listFiles(oy(".zip"))) != null) { for (int i = 0; i < listFiles.length; i++) { if (oz(listFiles[i].toString())) { F(listFiles[i]); } } File[] listFiles2 = parentFile.listFiles(oy(".zip")); if (listFiles2 != null && listFiles2.length > 15) { for (File file : listFiles2) { F(file); } } } } private boolean aXy() { new ehv(); return ehv.bX(this.mContext) == 1; } private String aXz() { String oB = oB("xml"); if (this.eRR && this.eRQ != null && G(new File(this.eRQ)) <= eRM) { File oA = oA(this.eRT); a(new File(this.eRQ), new File(oA.toString() + this.eRQ.substring(this.eRQ.lastIndexOf("/"), this.eRQ.length())), true); oA.toString(); } String str = oB + ".zip"; try { ehu.aP(oB, str); F(new File(oB)); return str; } catch (Exception e) { e.printStackTrace(); return null; } } private File oA(String str) { return this.mContext.getDir(str, 0); } private String oB(String str) { this.eRT = "crash" + "_" + SystemClock.uptimeMillis(); File oA = oA(this.eRT); if (oA != null) { try { FileOutputStream fileOutputStream = new FileOutputStream(new File(oA, str.equals("xml") ? "crashlog.xml" : "crashlog.txt")); ehx eie = str.equals("xml") ? new eie(this.mContext) : new ehy(this.mContext); if (this.eRO != null) { Throwable th = this.eRO; StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); th.printStackTrace(printWriter); printWriter.close(); this.eRP = stringWriter.toString(); } fileOutputStream.write(eie.a(this.eRP, this.eRs, this.eRu, this.eRv).getBytes()); fileOutputStream.close(); return oA.toString(); } catch (Exception e) { e.printStackTrace(); } } return null; } private FilenameFilter oy(final String str) { return new FilenameFilter() { /* class defpackage.eic.AnonymousClass1 */ public final boolean accept(File file, String str) { return str.endsWith(str); } }; } private boolean oz(String str) { HashMap hashMap = new HashMap(); hashMap.put("name", "testname"); HashMap hashMap2 = new HashMap(); hashMap2.put("userfile", str); return ehz.a("http://crashes.mo.wps.cn/errorReport/up", hashMap, hashMap2).contains("0"); } public final void run() { if (!this.eRU) { String aXz = aXz(); if (this.eRS && aXz != null) { if (((this.eRQ != null ? G(new File(this.eRQ)) : 0) <= eRN || aXy()) && oz(aXz)) { F(new File(aXz)); } } } else { aXx(); } if (this.eRV != null) { this.eRV.onFinish(); } } }